package com.prs.crm.action;

import org.apache.commons.io.FilenameUtils;

import java.io.FileInputStream;
import java.io.InputStream;

import org.courser.struts.BaseAction;

import com.prs.crm.service.ReportService;

@SuppressWarnings("serial")
public abstract class ReportAction extends BaseAction{
	
	private ReportService reportService;
	
	private InputStream inputStream;
	
	private String contentType;
	
	private String outFilePath;
	
	private String outfileName;
	
	private int exportType;
	
	public void setReportService(ReportService reportService) {
		this.reportService = reportService;
	}

	public ReportService getReportService() {
		return reportService;
	}

	public void setExportType(int exportType) {
		this.exportType = exportType;
	}

	public int getExportType() {
		return exportType;
	}



	public void setOutfileName(String outfileName) {
		this.outfileName = outfileName;
	}

	public String getOutfileName() {
		return outfileName;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public void setOutFilePath(String outFilePath) {
		
		this.outFilePath = outFilePath;
		this.setOutfileName(FilenameUtils.getName(outFilePath));
		String extendName = FilenameUtils.getExtension(outFilePath).toLowerCase();
		if (extendName.equals("pdf"))
		{
			this.setContentType("application/pdf");
		}
		else
		{
			this.setContentType("application/vnd.ms-excel");
		}
			
		try
		{
			if (this.inputStream!=null)
			{
				System.out.println(inputStream);
				inputStream.close();
				
			}
			inputStream = new FileInputStream(outFilePath);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public String getOutFilePath() {
		return outFilePath;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getContentType() {
		return contentType;
	}



}
